<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%@ page import="com.lmpop.trade.ti_orderinfo.Ti_orderinfoInfo" %>
<%@ page import="com.lmpop.trade.tb_ordergoods.Tb_ordergoodsInfo" %>
<%@ page import="com.lmpop.trade.tb_returngoodsdetail.Tb_returngoodsdetailInfo" %>
<%@ page import="com.lmpop.trade.ti_customer.Ti_customerInfo" %>
<%@ page import="com.lmpop.trade.ti_attach.Ti_attachInfo" %>
<%@ page import="java.util.*" %>
<%@ page import="com.lmpop.frame.util.PageTools" %>
<%@ page import="com.lmpop.trade.tb_commpara.Tb_commparaInfo" %>
<%@ page import="com.lmpop.frame.util.Config" %>
<%
	request.setCharacterEncoding("UTF-8");
	
	Map ti_orderinfo = new Hashtable();
	
	String s_order_id = "";
	if(request.getParameter("s_order_id")!=null && !request.getParameter("s_order_id").equals("")){
		s_order_id = request.getParameter("s_order_id");
		ti_orderinfo.put("order_no",s_order_id);
	}

	ti_orderinfo.put("user_id",user_id);
	ti_orderinfo.put("order_state","3");

	Ti_orderinfoInfo orderinfoInfo = new Ti_orderinfoInfo();
	String iStart = "0";
	int limit = 5;
	if(request.getParameter("iStart")!=null) iStart = request.getParameter("iStart");

	List list = orderinfoInfo.getPersonalListByPage(ti_orderinfo,Integer.parseInt(iStart),limit);
	int counter = orderinfoInfo.getPersonalCountByObj(ti_orderinfo);

	String pageString = new PageTools().getGoogleToolsBar(counter,"index.jsp?s_order_id="+s_order_id+"&iStart=",Integer.parseInt(iStart),limit);
	
	Tb_returngoodsdetailInfo returngoodsdetail = new Tb_returngoodsdetailInfo();
	Tb_ordergoodsInfo tb_ordergoodsInfo = new Tb_ordergoodsInfo();
	Ti_customerInfo  ti_customerInfo  = new Ti_customerInfo();
	Ti_attachInfo  ti_attachInfo = new Ti_attachInfo(); 

	List goodslist = new LinkedList();    

	Map returnmap = new Hashtable();

	Tb_commparaInfo commparaInfo = new Tb_commparaInfo();

	Config configa = new Config();
	String goods_article_path = configa.getString("goods_article_path");
	String company_shop_path = configa.getString("company_shop_path");

%>
<div class="f-right w750">

	<form action="chooseindex.jsp" name="homeForm" method="post">
    <table width="100%" border="0" cellspacing="0" cellpadding="0" >
      <tr>
        <td><table width="100%" border="0" cellpadding="0" cellspacing="0" bgcolor="#eddfea">
            <tr>
              <td width="5%" height="40" align="center"><img src="/program/member/index/images/gl_03.jpg" width="22" height="22"></td>
              <td width="75%"><h3>选择退货商品</h3></td>
			  <td width="20%"><a href="index.jsp?menu_id=<%=menu_id%>" class="cZs">返回列表>></a></td>
            </tr>
          </table>
		  
		  <div class="ts"> <img src="/program/member/index/images/ts.gif" /> 先选择订单,再选择需要退货的商品. 已申请退货的商品不得再次申请,只能查看处理情况。</div>
		  
          <table width="100%" border="0" cellspacing="0" cellpadding="0"  style="border-bottom:1px dashed #acacac; border-top:1px dashed #acacac;">
            <tr>
              <td height="45" align="left">
              	订单号:<input name="s_order_id" id="s_order_id" type="text" class="input" />
                &nbsp;&nbsp;
				
                <input name="searchInfo" type="submit" value="搜索" onclick="search()"/>	
            </tr>
          </table>
         
          <table width="100%" bgcolor="#eddfea"  cellspacing="1" cellpadding="1">
            <tr>
				<th align="left"><input type="button" name="Submit2" value="提交退货商品" onclick="checkReturnGoods()" class="button2" /></th>
		  		<th align="left">订单基本信息</th>
				<th>状态</th>  	
				
            </tr>
          </table>
          <% 
          		int listsize = 0;
				if(list!=null && list.size()>0){
					Hashtable map = new Hashtable();
					Hashtable goodsmap = new Hashtable();
					listsize = list.size();
					for(int i=0;i<list.size();i++){
					map = (Hashtable)list.get(i);
					String order_id="",order_no="",all_paid_amount="",add_time="",order_state="",all_goods_amount="";
					String cust_id="",shop_name="";
					if(map.get("cust_id")!=null) cust_id = map.get("cust_id").toString();
					if(map.get("shop_name")!=null) shop_name = map.get("shop_name").toString();
					if(map.get("order_id")!=null) order_id = map.get("order_id").toString();
					if(map.get("order_no")!=null) order_no = map.get("order_no").toString();
					if(map.get("all_paid_amount")!=null) all_paid_amount = map.get("all_paid_amount").toString();
					if(map.get("all_goods_amount")!=null) all_goods_amount = map.get("all_goods_amount").toString();
					if(map.get("add_time")!=null) add_time = map.get("add_time").toString();
					if(map.get("order_state")!=null) order_state = map.get("order_state").toString();
					if(add_time.length()>19)add_time=add_time.substring(0,19);

					String state_name = commparaInfo.getOneComparaPcode1("31",order_state);
					String custUrl = company_shop_path + cust_id;

		  %>
          <table width="100%" style="border:1px solid #cecece;" cellpadding="1" cellspacing="1" id="line<%=i%>">
			<tr>
				<td height="30" colspan="7" style="background:#EBEBEB;">	
					<input type="radio" name="order" onclick="selectOrder()">
					订单编号:<%=order_no%>
					&nbsp;
					成交时间: <span style="color:#666666;"><%=add_time%></span>
				    <span style="color:#666666;">
					   <a href="<%=custUrl%>" target="_blank"><font color="#BB8600"><%=shop_name%></font></a>
					</span>
				</td>
			</tr>
           
			<%  
				goodslist = null;//tb_ordergoodsInfo.getListByTable(order_id);
				int checksize =0;        
				if(goodslist!=null && goodslist.size()>0){
					checksize = goodslist.size();    
					for(int k=0;k<checksize;k++){
					goodsmap = (Hashtable)goodslist.get(k);
					String trade_id="",goods_name="",goods_num="",paid_amount="",shop_price="",goods_id="";
					if(goodsmap.get("trade_id")!=null) trade_id = goodsmap.get("trade_id").toString();
					if(goodsmap.get("goods_id")!=null) goods_id = goodsmap.get("goods_id").toString();
					if(goodsmap.get("goods_name")!=null) goods_name = goodsmap.get("goods_name").toString();
					if(goodsmap.get("goods_num")!=null) goods_num = goodsmap.get("goods_num").toString();
					if(goodsmap.get("shop_price")!=null) shop_price = goodsmap.get("shop_price").toString();
					
					returnmap.put("order_no",order_no);
					returnmap.put("goods_id",goods_id);
					String back_state = returngoodsdetail.getReturnGoodsState(returnmap);
					
					String returnstate = "";
					if(back_state.equals(""))returnstate = "未申请";
					else if(back_state.equals("0"))returnstate = "未处理";
					else if(back_state.equals("1"))returnstate = "处理中";
					else if(back_state.equals("2") || back_state.equals("3"))returnstate = "处理完成";

					String compnay ="";
					if(!cust_id.equals("")){
					   compnay  = ti_customerInfo.getCustNameByCustId(cust_id);         
					}
					String img_path =  ti_attachInfo.getFilePathByAttachrootid(goods_id);
					if(img_path.equals("")){
						 img_path ="/program/member/images/cpwu.gif";            
					}
			%>
			<table width="100%" style="border-bottom:1px solid #cecece;" cellpadding="1" cellspacing="1">
			<tr height="80">
				<td width="5%" align="left">
					<input type="checkbox" name="check_<%=i%>_<%=k%>" id="check_<%=i%>_<%=k%>" onclick="ifStateNull()" disabled value="<%=trade_id%>" />
					<input type="hidden" name="cust_id_<%=i%>_<%=k%>" id="cust_id_<%=i%>_<%=k%>" value="<%=cust_id%>" />
					<input type="hidden" name="state_<%=i%>_<%=k%>" id="state_<%=i%>_<%=k%>" value="<%=back_state%>" />
				</td>
				<td width="12%" align="left"><img src="<%=img_path%>" width="80" height="80" /></td>
				<td width="63%" align="left" style="border-right:1px solid #cecece;">
					<span style="color:#303A43;">商品信息:</span>	
					<%=goods_name%>&nbsp;<span style="color:#666666;">(购买数量:<%=goods_num%> 付款:<%=shop_price%>)</span><br/>
					<span style="color:#303A43;">发布商家: </span><%=compnay%>
				</td>
				<td width="10%" align="left"><%=returnstate%></td>
				
				
            </tr>
			</table>
			<%
					}
				}
			%>
			<input type="hidden" name="checksize_<%=i%>" id="checksize_<%=i%>" value="<%=checksize%>" />	
          </table>
          <%
          		}
          	}
          %>
          
          <table width="100%" border="0" cellpadding="0" cellspacing="0">
            <tr>
              <td width="4%" height="35" align="center">
              	<%=pageString%>
				
              </td>
            </tr>
          </table>

           <table width="100%" border="0" cellpadding="0" cellspacing="0">
            <tr>
              <td align="center">
              	<input type="hidden" name="listsize" id="listsize" value="<%=listsize %>" />
				<input type="hidden" name="menu_id" id="menu_id" value="<%=menu_id %>" />
				<input type="hidden" name="user_id" value="<%=user_id%>" />
			  </td>
            </tr>
          </table>

        </td>
      </tr>
    </table>
   </form>
  </div>